-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix incorrect example in wide_to_long docstring #25736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## master #25736 +/- ##
=======================================
Coverage 91.25% 91.25%
=======================================
Files 172 172
Lines 52973 52973
=======================================
Hits 48338 48338
Misses 4635 4635
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25736 +/- ##
=======================================
Coverage 91.26% 91.26%
=======================================
Files 173 173
Lines 52982 52982
=======================================
Hits 48356 48356
Misses 4626 4626
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you post the output of python scripts/validate_docstrings.py pandas.wide_to_long
And, it's not necessary, but it would be good to run all these in CI. Can you add
diff --git a/ci/code_checks.sh b/ci/code_checks.sh
index 51df77934..5ab33e7e2 100755
--- a/ci/code_checks.sh
+++ b/ci/code_checks.sh
@@ -223,6 +223,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
MSG='Doctests top-level reshaping functions' ; echo $MSG
pytest -q --doctest-modules \
pandas/core/reshape/concat.py \
+ pandas/core/reshape/melt.py \
pandas/core/reshape/pivot.py \
pandas/core/reshape/reshape.py \
pandas/core/reshape/tile.py \
and ensure that things pass with pytest --doctest-modules pandas/core/reshape/melt.py
. May need to change a couple more things.
pandas/core/reshape/melt.py
Outdated
@@ -386,7 +386,7 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'): | |||
8 3 3 2.1 2.9 | |||
|
|||
>>> l = pd.wide_to_long(df, stubnames='ht', i=['famid', 'birth'], j='age', | |||
sep='_', suffix='\w') | |||
sep='_', suffix='\w+') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need ...
under the >>>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errors:
################################### Doctests ###################################
################################################################################
**********************************************************************
Line 94, in pandas.wide_to_long
Failed example:
df
Expected:
birth famid ht1 ht2
0 1 1 2.8 3.4
1 2 1 2.9 3.8
2 3 1 2.2 2.9
3 1 2 2.0 3.2
4 2 2 1.8 2.8
5 3 2 1.9 2.4
6 1 3 2.2 3.3
7 2 3 2.3 3.4
8 3 3 2.1 2.9
Got:
famid birth ht1 ht2
0 1 1 2.8 3.4
1 1 2 2.9 3.8
2 1 3 2.2 2.9
3 2 1 2.0 3.2
4 2 2 1.8 2.8
5 2 3 1.9 2.4
6 3 1 2.2 3.3
7 3 2 2.3 3.4
8 3 3 2.1 2.9
**********************************************************************
Line 154, in pandas.wide_to_long
Failed example:
df # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
Expected:
A(quarterly)-2010 A(quarterly)-2011 B(quarterly)-2010 ...
0 0.548814 0.544883 0.437587 ...
1 0.715189 0.423655 0.891773 ...
2 0.602763 0.645894 0.963663 ...
X id
0 0 0
1 1 1
2 1 2
Got:
A(quarterly)-2010 A(quarterly)-2011 B(quarterly)-2010 B(quarterly)-2011 X id
0 0.548814 0.544883 0.437587 0.383442 0 0
1 0.715189 0.423655 0.891773 0.791725 1 1
2 0.602763 0.645894 0.963663 0.528895 1 2
**********************************************************************
Line 195, in pandas.wide_to_long
Failed example:
df
Expected:
birth famid ht_one ht_two
0 1 1 2.8 3.4
1 2 1 2.9 3.8
2 3 1 2.2 2.9
3 1 2 2.0 3.2
4 2 2 1.8 2.8
5 3 2 1.9 2.4
6 1 3 2.2 3.3
7 2 3 2.3 3.4
8 3 3 2.1 2.9
Got:
famid birth ht_one ht_two
0 1 1 2.8 3.4
1 1 2 2.9 3.8
2 1 3 2.2 2.9
3 2 1 2.0 3.2
4 2 2 1.8 2.8
5 2 3 1.9 2.4
6 3 1 2.2 3.3
7 3 2 2.3 3.4
8 3 3 2.1 2.9
and after my attempted fix,
################################################################################
################################### Doctests ###################################
################################################################################
**********************************************************************
Line 154, in pandas.wide_to_long
Failed example:
df # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
Expected:
A(quarterly)-2010 A(quarterly)-2011 B(quarterly)-2010 ...
0 0.548814 0.544883 0.437587 ...
1 0.715189 0.423655 0.891773 ...
2 0.602763 0.645894 0.963663 ...
X id
0 0 0
1 1 1
2 1 2
Got:
A(quarterly)-2010 A(quarterly)-2011 B(quarterly)-2010 B(quarterly)-2011 X id
0 0.548814 0.544883 0.437587 0.383442 0 0
1 0.715189 0.423655 0.891773 0.791725 1 1
2 0.602763 0.645894 0.963663 0.528895 1 2
The ELLIPSIS is not being considered or ignored by doctest as it ought to be. Perhaps another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doctest, and hence the entire pipeline is failing only due to this ELLIPSIS error @TomAugspurger any suggestions on what to do? (If I put all columns, pylint
and flake8
fails because it exceeds 79 chars)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does |
Looks like you're close! https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=9462&view=logs&jobId=10b0523a-38de-5c7a-02e7-c2259d583b33&taskId=72638d9d-eff6-5eec-7c2f-7fe1a320272e&lineStart=37&lineEnd=38&colStart=1&colEnd=1 You can hopefully fit all the columns in a line. |
pandas/core/reshape/melt.py
Outdated
0 0.548814 0.544883 0.437587 ... 0 0 | ||
1 0.715189 0.423655 0.891773 ... 1 1 | ||
2 0.602763 0.645894 0.963663 ... 2 2 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can delete this line I think.
0 0 0 | ||
1 1 1 | ||
2 1 2 | ||
A(quarterly)-2010 A(quarterly)-2011 B(quarterly)-2010 ... X id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the output too wide to include all the columns without any ellipses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @TomAugspurger the line is too wide to include all columns, so deleted only "B(quarterly)-2011" column (88 > 79 chars on pycodestyle
and flake8
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm, that's a little unfortunate as all the columns are important :/
Well, for now, let's use ellipses. FYI, your spacing is just slightly off, so it failed again :)
diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py
index cec4c609c..df144db50 100644
--- a/pandas/core/reshape/melt.py
+++ b/pandas/core/reshape/melt.py
@@ -334,9 +334,9 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'):
>>> df['id'] = df.index
>>> df # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
A(quarterly)-2010 A(quarterly)-2011 B(quarterly)-2010 ... X id
- 0 0.548814 0.544883 0.437587 ... 0 0
- 1 0.715189 0.423655 0.891773 ... 1 1
- 2 0.602763 0.645894 0.963663 ... 2 2
+ 0 0.548814 0.544883 0.437587 ... 0 0
+ 1 0.715189 0.423655 0.891773 ... 1 1
+ 2 0.602763 0.645894 0.963663 ... 1 2
>>> pd.wide_to_long(df, ['A(quarterly)', 'B(quarterly)'], i='id',
... j='year', sep='-')
I think you need an extra space so that the values in id
are under the d
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls merge master
Closing as stale and superseded by #26010 |
IIRC this was quite close. Just a whitespace issue. I’d prefer we push it across the line if a maintainer or the original author has time.
… On Apr 10, 2019, at 00:32, William Ayd ***@***.***> wrote:
Closed #25736.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
git diff upstream/master -u -- "*.py" | flake8 --diff